<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/navigationRight.jsp" %>
<%@include file="/WEB-INF/jsp/common/head.jsp" %>
<%@include file="/WEB-INF/jsp/common/navigationLeft.jsp" %>

<div class="m2-userCentersettings-con">
    <%-- <form method="POST" action="/user/change">--%>
    <%--存放userId的隐藏域--%>
    <input type="hidden" name="id" value="${aqbUser.userId}" />
    <!--您现在的安全级别-->
    <div class="m2-userCentersettings-bg">
        <div class="m2-wel-level m2-userSettings-level">
            <div class="m2-level-image">
                <b class="m2-wel-levelTip">您现在的安全级别</b>
                <b class="m2-userSettingslevel-low" id='safe_level'></b>
                <i class="m2-levelIcon-fal"></i>
                <i class="m2-levelIcon-fal"></i>
                <i class="m2-levelIcon-fal"></i>
                <b class="m2-wel-levelTip">请通过完善下方信息来提升安全级别</b>
            </div>
        </div>
        <ul>
            <li class="m2-userCentersettings-step1 m2-userSettings-step">


                <ul class="m2-userSettings-setpHide" style="display:none;" id='phone_status_1'>
                    <!-- 						<li class="m2-userSettingshide-tit"> -->
                    <!-- 							可添加说明文字可添加说明文字可添加说明文字 -->
                    <!-- 						</li> -->

                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>手机号：</span>
                        <input type="text" placeholder="请输新手机号码" type="text" id='vp-phonenum' value="${userSession.phone}">
                        <a class="m2-userSettings-telSubmit" href="javascript:void(0)" id='vp-textbtn'>短信验证码</a>
                        <a class="m2-userSettings-telSubmit" href="javascript:void(0)" id='vp-voicebtn'>语音验证码</a>
                        <span class="m2-userSettingshide-warning"
                              style='margin-left: 80px;margin-top: 10px;display: none;' id='vp-warn'><em></em>请输入正确的手机号。</span>
                        <span class="m2-userSettingshide-success m2-userSettingshide-successTel" style='display: none'
                              id='vp-msg'><em></em>验证码已发出,如果您在2分钟之内未收到验证码,请再次获取验证码</span>
                    </li>
                    <li style="display:none;" id='verifyphoneli'>
                        <span class="m2-userSettingshide-nor"><u>*</u>验证图码：</span>
                        <input type="text" placeholder="请输入图片验证码" type="text" id='vp-vpic'>
                        <img src="code.png" width="104" height="42" style="cursor: pointer"
                             onclick="document.getElementById('reverifyCode').src='code.png?time='+Math.random();void(0);"
                             id="reverifyCode"/>
                        <span class="m2-userSettingshide-warning"></span>
                    </li>
                    <li>
                        <span class="m2-userSettingshide-nor"><u>*</u>验证码：</span>
                        <input type="text" placeholder="请输入收到的验证码" type="text" id='vp-text'>
                    </li>
                    <li class="m2-userSettingshide-btn"><a href="javascript:void(0)" id='vp-submit'>修改</a></li>
                </ul>
            </li>
            <li class="m2-userCentersettings-step2 m2-userSettings-step"></li>


            <li class="m2-userCentersettings-step4 m2-userSettings-step"></li>


            <li class="m2-userCentersettings-step6 m2-userSettings-step">
                <form method="POST" action="/user/findPwd">
                    <div class="m2-userSettings-stepShow">
                        <i></i>
                        <span class="m2-userSettingsshow-tit">登录密码</span>
                        <span class="m2-userSettingsshow-exp">上次登录时间：</span>
                        <span class="m2-userSettingsaut m2-userSettingsaut-tur"><b></b>已设置</span>
                        <span class="m2-userSettingsshow-link"><a href="javascript:void(0)">修改</a></span>
                    </div>
                    <ul class="m2-userSettings-setpHide">
                        <li>
                            yomghuming:${userCode}
                            <input type="hidden" value="${userCode}" name="userCode">
                        </li>
                        <li>
                            <input type="hidden" value="${email}" name="email">
                        </li>
                        <li>
                            <span class="m2-userSettingshide-nor"><u>*</u>新密码：</span>
                            <input type="password" placeholder="请输入新密码" name="password" type="text" id='newpass1'>
                            <span class="m2-userSettingshide-warning"></span>
                        </li>
                        <li>
                            <span class="m2-userSettingshide-nor"><u>*</u>确认密码：</span>
                            <input type="password" placeholder="请再次输入新密码"  type="text" id='newpass2'>
                            <span class="m2-userSettingshide-warning"></span>
                        </li>
                        <li class="m2-userSettingshide-btn"><input style="background-color: #2fb7ea" type="submit" href="javascript:void(0)" id='setpass-btn' value="确认"/></li>
                    </ul>
                </form>
            </li>
        </ul>
    </div>
    </form>
</div>

<script type="text/javascript" src="/statics/statics/home2/js/HMZCity.json?20160520"></script>
<script type="text/javascript">
    $(function () {
        $user_type = 1;
        //点击修改按钮展开选项
        $('.m2-userSettings-setpHide').hide();
        $('.m2-userSettingsshow-link a').click(function () {
            $(this).parents('.m2-userSettings-stepShow').siblings('.m2-userSettings-setpHide').toggle(500);
        });
        setVerifyStatus();
        bindphone();
        setPassword();
        setAddress();
        verifyemail();
        getQuestionnaire();
        hsChangePassWord();

        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) {
                return unescape(r[2]);
            }
            return null;
        }


        var xl = getQueryString("isXl");
        if (xl == "1") {
            $("#hsmmsz").trigger("click");
        }
        var xg = getQueryString("isXg");
        if (xg == "1") {
            $("#hsmmxg").trigger("click");
        }
    });

    function setVerifyStatus() {

        var id_status = 0;
        var address_status = 0;
        var email_status = 0;
        var phone_status = 1;
        var questionnaire_status = 0;
        var setword_status = 0;
        var i = Number(id_status) + Number(phone_status) + Number(email_status);

        if (i == 1) {
            $('#safe_level').text('低');
        } else if (i == 2) {
            $('#safe_level').text('中');
        } else if (i == 3) {
            $('#safe_level').text('高');
        } else {
            $('#safe_level').text('极低');
        }
        var j = 0;
        $('.m2-levelIcon-fal').each(function () {
            if (j < i) {
                $(this).prop('class', 'm2-levelIcon-tur');
                j++;
            }
        });
        if (id_status == 1) {
            $('#id_status').removeClass('m2-userSettingsaut-fal');
            $('#id_status').addClass('m2-userSettingsaut-tur');
            $('#id_status').html('<b></b>已认证');
            $('#id_status').next('span').find('a').text('查看');
            $('#id_status').next('span').find('a').prop('href', '#');
            $('#tid_status').removeClass('m2-userSettingsaut-fal');
            $('#tid_status').addClass('m2-userSettingsaut-tur');
            $('#tid_status').html('<b></b>已认证');
            $('#tid_status').next('span').find('a').text('查看');
            $('#tid_status').next('span').find('a').prop('href', '#');
        }
        if (phone_status == 1) {
            $('#phone_status').removeClass('m2-userSettingsaut-fal');
            $('#phone_status').addClass('m2-userSettingsaut-tur');
            $('#phone_status').html('<b></b>已绑定');
            $('#phone_status').next('span').find('a').text('修改');
            $('#phone_status_2').remove();
            if (3 < 0) {
                $('#verifyphoneli').show();
            }
        }
        if (3 < 0) {
            $('#verifyphoneli').show();
        }
        if (email_status == 1) {
            $('#email_status').removeClass('m2-userSettingsaut-fal');
            $('#email_status').addClass('m2-userSettingsaut-tur');
            $('#email_status').html('<b></b>已验证');
            $('#email_status').next('span').find('a').text('修改');
        }
        if (address_status == 1) {
            $('#address_status').removeClass('m2-userSettingsaut-fal');
            $('#address_status').addClass('m2-userSettingsaut-tur');
            $('#address_status').html('<b></b>已添加');
            $('#address_status').next('span').find('a').text('修改');
        }
        if (questionnaire_status == 1) {
            $('#questionnaire_status').removeClass('m2-userSettingsaut-fal');
            $('#questionnaire_status').addClass('m2-userSettingsaut-tur');
            $('#questionnaire_status').html('<b></b>已填写');
            $('#questionnaire_status').next('span').find('a').text('查看');
            $('#questionnaire-text').text('因时制宜，期待每一次改变');
            $('.question_subbtn').hide();
        }
        if (getParam('phone') == 1) {
            $('#phone_status').next('span').find('a').click();
        }
        if (getParam('email') == 1) {
            $('#email_status').next('span').find('a').click();
        }
        if (getParam('hspassword') == 1) {
            $('#email_status').next('span').find('a').click();
        }
    }

    function bindphone() {

        var flag = false;
        var t1 = 0, t2 = 0;
        var reg = /^1\d{10}$/;

        if (reg.test($('#vp-phonenum').val())) {
            flag = true;
        } else {
            flag = false;
        }
        $('#vp-phonenum').keyup(function () {
            if (reg.test($('#vp-phonenum').val())) {
                $('#vp-warn').hide();
                flag = true;
            } else {
                $('#vp-warn').show();
                flag = false;
            }
        });
        $('#vp-textbtn').click(function () {
            t2 = Date.now();
            if (t2 - t1 > 60 * 1000 && flag) {
                t1 = Date.now();
                $.ajax({
                    url: "/usercenter-Accountcontrol-sendphone",
                    type: "POST",
                    data: {
                        cellphone: $('#vp-phonenum').val(),
                        vcode: $('#vp-vpic').val()
                    },
                    success: function (data) {
                        var obj = eval('(' + data + ')');
                        if (obj.status == 2) {
                            $('#vp-msg').show();
                            dialog(obj);
                        } else {
                            dialog(obj);
                        }
                    }
                });
                if ($(this).hasClass('m2-userSettings-telSubmit')) {
                    $(this).removeClass('m2-userSettings-telSubmit');
                    $(this).addClass('m2-userSettings-telSubmit-disabled');
                    setTimeout(function () {
                        $('#vp-textbtn').removeClass('m2-userSettings-telSubmit-disabled');
                        $('#vp-textbtn').addClass('m2-userSettings-telSubmit');
                        $('#vp-msg').hide();
                    }, 60000);
                }
            }
        });
        $('#vp-voicebtn').click(function () {
            t2 = Date.now();
            if (t2 - t1 > 60 * 1000 && flag) {
                t1 = Date.now();
                $.ajax({
                    url: "/usercenter-Accountcontrol-sendvoice",
                    type: "POST",
                    data: {
                        cellphone: $('#vp-phonenum').val(),
                        vcode: $('#vp-vpic').val()
                    },
                    success: function (data) {
                        obj = eval('(' + data + ')');
                        if (obj.status == 2) {
                            $('#vp-msg').show();
                            dialog(obj);
                        } else {
                            dialog(obj);
                        }
                    }
                });
                if ($(this).hasClass('m2-userSettings-telSubmit')) {
                    $(this).removeClass('m2-userSettings-telSubmit');
                    $(this).addClass('m2-userSettings-telSubmit-disabled');
                    setTimeout(function () {
                        $('#vp-voicebtn').removeClass('m2-userSettings-telSubmit-disabled');
                        $('#vp-voicebtn').addClass('m2-userSettings-telSubmit');
                        $('#vp-msg').hide();
                    }, 60000);
                }
            }
        });
        $('#vp-submit').click(function () {
            if (flag) {
                t1 = Date.now();
                $.ajax({
                    url: "/usercenter-Accountcontrol-verifyPhone",
                    type: "POST",
                    data: {
                        cellphone: $('#vp-phonenum').val(),
                        code: $('#vp-text').val()
                    },
                    success: function (data) {
                        obj = eval('(' + data + ')');
                        dialog(obj);
                    }
                });
            }
        });
    }





    function setPassword() {

        var flag1 = false;
        var flag2 = false;
        var flag3 = false;

        $('#oldpass').keyup(function () {
            if ($('#oldpass').val().length > 5 && $('#oldpass').val().length < 16) {
                $('#oldpass').next('span').html('');
                flag1 = true;
            } else {
                $('#oldpass').next('span').html('<em></em>密码需为6-15常用英文字母或数字。');
                flag1 = false;
            }
        });
        $('#newpass1').keyup(function () {
            if ($('#newpass1').val().length > 5 && $('#newpass1').val().length < 16) {
                $('#newpass1').next('span').html('');
                flag2 = true;
            } else {
                $('#newpass1').next('span').html('<em></em>密码需为6-15常用英文字母或数字。');
                flag2 = false;
            }
        });
        $('#newpass2').keyup(function () {
            if ($('#newpass2').val() == $('#newpass1').val()) {
                $('#newpass2').next('span').html('');
                flag3 = true;
            } else {
                $('#newpass2').next('span').html('<em></em>两次输入密码须一致！');
                flag3 = false;
            }
        });
        $('#setpass-btn').click(function () {

            if (flag1 && flag2 && flag3) {
                $.ajax({
                    url: "/usercenter-Accountcontrol-setPassWord",
                    type: "POST",
                    data: {
                        oldpass: $('#oldpass').val(),
                        newpass: $('#newpass2').val()
                    },
                    success: function (data) {
                        obj = eval('(' + data + ')');
                        dialog(obj);
                        $('#oldpass').val('');
                        $('#newpass1').val('');
                        $('#newpass2').val('');
                    }
                });
            }
        });
    }


        oldanwser = '';
        anwserobj = oldanwser.split(',');
        $('#questionnaire li').has('ul').each(function (i) {
            if (anwserobj[i]) {
                var subanwser = anwserobj[i].split(':');
                $(this).find('input').each(function () {
                    for (var j in subanwser) {
                        if (subanwser[j] == $(this).next('label').text().substr(0, 1)) {
                            $(this).prop("checked", "checked");
                        }
                    }
                });
            }

    });

    function closeDialog() {
        $('.m2-userCentercommon-confirm').hide();
        $('.m2-userCentercommon-bg').hide();
    }

    function dialog(obj) {
        var dom = '<span class="m2-userCentercommon-confirmClose" onclick="closeDialog()"></span>';
        if (obj['status'] == 1 || obj['status'] == 2) {
            dom += '<p class="m2-userCommon-confirmSuc"><i></i>';
        } else {
            dom += '<p class="m2-userCommon-confirmWar"><i></i>';
        }
        if (obj['msg']) {
            dom += obj['msg'] + '</p>';
        } else if (obj['message']) {
            dom += obj['message'] + '</p>';
        } else {
            return;
        }
        if (obj['status'] == 1) {
            dom += '<p class="m2-userCommon-confirmBtn"><a class="m2-user-confirmBtn" onclick="window.location.reload();">确&nbsp;定</a></p>';
        } else if (obj['status'] == 2) {
            dom += '<p class="m2-userCommon-confirmBtn"><a class="m2-user-confirmBtn" onclick="closeDialog()">确&nbsp;定</a></p>';
        } else {
            dom += '<p class="m2-userCommon-confirmBtn"><a class="m2-user-confirmBtn" onclick="closeDialog()">确&nbsp;定</a></p>';
        }
        $('.m2-userCentercommon-confirm').html(dom);
        $('.m2-userCentercommon-confirm').show();
        $('.m2-userCentercommon-bg').show();
    }

    //用户名变化
    $('#usernametext').keyup(function () {
        userNameCheck($(this).val());
    });

    //用户名检查
    function userNameCheck(username) {

        var patten1 = /^([0-9]|[a-z]|[A-Z]|_)+$/;
        var patten2 = /^([a-z]|[A-Z])/;
        var patten3 = /^.{6,15}$/;
        username.trim();

        if (!patten1.test(username)) {
            userNameWarn('用户名只允许字母、数字、下划线组成');
            return false;
        } else if (!patten2.test(username)) {
            userNameWarn('用户名首位只能为字母');
            return false;
        } else if (!patten3.test(username)) {
            userNameWarn('用户名长度应为6-15位');
            return false;
        } else {
            userNameWarn('')
            return true;
        }
    }

    //修改用户名错误
    function userNameWarn(msg) {
        if (msg) {
            $('#usernamewarn').html('<em></em>' + msg);
        } else {
            $('#usernamewarn').html('');
        }
    }

    function hsChangePassWord() {
        var t1 = 0
        $('#hsvp-textbtn').click(function () {
            t2 = Date.now();
            if (t2 - t1 > 60 * 1000) {
                t1 = Date.now();
                $.ajax({
                    url: "/usercenter-Accountcontrol-hs_sendphone",
                    type: "POST",
                    data: {
                        cellphone: $('#hsvp-phonenum').val(),
                    },
                    success: function (data) {
                        var obj = eval('(' + data + ')');
                        mo2_regTim();
                        dialog(obj);
                    }
                });
                if ($(this).hasClass('m2-userSettings-telSubmit')) {
                    $(this).removeClass('m2-userSettings-telSubmit');
                    $(this).addClass('m2-userSettings-telSubmit-disabled');
                    setTimeout(function () {
                        $('#hsvp-textbtn').removeClass('m2-userSettings-telSubmit-disabled');
                        $('#hsvp-textbtn').addClass('m2-userSettings-telSubmit');
                    }, 60000);
                }
            }
        });
        $('#hsChange-btn').click(function () {
            var hsvp_phonenum = $("#hsvp-phonenum").val();
            var hs_code = $("#hs_code").val();
            var hs_name = $("#hs_name").val();
            var hs_idCard = $("#hs_idCard").val();

            if ($user_type == 1) {
                var regu = /(^[0-9]{15}$)|([0-9]{17}([0-9]|X|x)$)/;
                var re = new RegExp(regu);
                if (!re.test(hs_idCard)) {
                    var obj = new Array();
                    obj['msg'] = "身份证格式不正确";
                    obj['status'] = 0;
                    dialog(obj);
                    return false;
                }
            }

            if (hs_code == "" || hs_name == "" || hs_idCard == "") {
                var obj = new Array();
                obj['msg'] = "您需要填写全部信息才能提交";
                obj['status'] = 0;
                dialog(obj);
                return;
            } else {

                $.ajax({
                    url: "usercenter-Accountcontrol-hs_changePassWord",
                    type: "POST",
                    dataType: "json",
                    data: {
                        hs_code: hs_code,
                        hs_name: hs_name,
                        hs_idCard: hs_idCard,
                        hsvp_phonenum: hsvp_phonenum
                    },
                    success: function (data) {
                        if (data.status == 3) {
                            window.location.href = "/cupdata-Capital-setting";
                        } else {
                            dialog(data);
                        }
                    }
                });
            }
        });

        // 注册倒计时
        var regTim = 60; //剩余时间
        function mo2_regTim() {
            if (regTim > 0) {
                $('#hsvp-textbtn').html(regTim + '秒后重新发送');
                regTim--;
                setTimeout(function () {
                    mo2_regTim();
                }, 1000);
            }
            else if (regTim <= 0) {
                regTim = 60;
                $('#hsvp-textbtn').removeClass('m2-userSettings-telSubmit-disabled');
                $('#hsvp-textbtn').addClass('m2-userSettings-telSubmit');
                //$('.mo2-indRegtim').addClass('mo2-regTin-able').removeClass('mo2-regTin-unable');
                $('#hsvp-textbtn').html('重新发送');
            }
        }


    }
</script>

</body>
</html>
